<h2>学校基本信息</h2>
<table border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td><label for="area">学校所在地区：</label></td>
    <td><span id="area-title"><%= @school.area.blank? ? "未选择地区" : @school.area.title %></span> <%= link_to_remote "选择", :url => {:controller => 'areas', :action => 'list', :id => @school.area}, :before => "Element.hide('areas-list');Element.hide('areas-list-notice');Element.show('areas-list-spinner')" %></td>
  </tr>
  <tr>
    <td colspan="2">
      <div id="areas-list-spinner" style="display:none;color:gray;">正在获得地区列表 ...</div>
      <div id="areas-list-notice" style ="display:none;color:gray;"></div>
      <div id="areas-list" style="display:none;"></div>
      <%= form.hidden_field :area_id %>
    </td>
  </tr>
  <tr>
    <td><label for="title">学校名称：</label></td>
    <td><%= form.text_field :title %><br />
      <span class="tip">不用填写省，比如：丽江市宁蒗县永宁乡温泉完小</span></td>
  </tr>
  <tr>
    <td><label for="address">学校地址：</label></td>
    <td><%= form.text_field :address %></td>
  </tr>
  <tr>
    <td><label for="zipcode">邮政编码：</label></td>
    <td><%= form.text_field :zipcode %></td>
  </tr>
  <tr>
    <td><label for="master">校长姓名：</label></td>
    <td><%= form.text_field :master %></td>
  </tr>
  <tr>
    <td><label for="telephone">学校电话：</label></td>
    <td><%= form.text_field :telephone %></td>
  </tr>
  <tr>
    <td><label for="contact_name">学校联系人：</label></td>
    <td><%= form.text_field :contact_name %></td>
  </tr>
  <tr>
    <td><label for="contact_role">联系人职务/身份：</label></td>
    <td><%= form.text_field :contact_role %></td>
  </tr>
  <tr>
    <td><label for="contact_telephone">联系人电话：</label></td>
    <td><%= form.text_field :contact_telephone %></td>
  </tr>
  <tr>
    <td><label for="contact_email">联系人邮箱/QQ：</label></td>
    <td><%= form.text_field :contact_email %></td>
  </tr>
  <tr>
    <td><label for="level_amount">学制：</label></td>
    <td><%= form.text_field :level_amount %></td>
  </tr>
  <tr>
    <td><label for="teacher_amount">教职工数：</label></td>
    <td><%= form.text_field :teacher_amount %></td>
  </tr>
  <tr>
    <td><label for="class_amount">班级数：</label></td>
    <td><%= form.text_field :class_amount %></td>
  </tr>
  <tr>
    <td><label for="student_amount">在校生数：</label></td>
    <td><%= form.text_field :student_amount %></td>
  </tr>
  <tr>
    <td><label for="has_library">是否有图书室：</label><br />
        <label for="book_amount">现有图书：</label></td>
    <td><%= form.radio_button :has_library, Status::School::RadioBox::YES %> 是，<%= form.radio_button :has_library, Status::School::RadioBox::NO %> 否，<%= form.radio_button :has_library, Status::School::RadioBox::UNKNOWN %> 未知<br />
        <%= form.text_field :book_amount, :size => 10 %> 册</td>
  </tr>
  <tr>
    <td><label for="has_pc">是否有电脑：</label><br />
        <label for="pc_amount">现有电脑：</label><br />
        <label for="has_internet">是否能上网：</label></td>
    <td><%= form.radio_button :has_pc, Status::School::RadioBox::YES %>是，<%= form.radio_button :has_pc, Status::School::RadioBox::NO %> 否，<%= form.radio_button :has_pc, Status::School::RadioBox::UNKNOWN %>未知<br />
        <%= form.text_field :pc_amount, :size => 10 %> 台<br />
        <%= form.radio_button :has_internet, Status::School::RadioBox::YES %>是，<%= form.radio_button :has_internet, Status::School::RadioBox::NO %> 否，<%= form.radio_button :has_internet, Status::School::RadioBox::UNKNOWN %> 未知</td>
  </tr>
  <tr>
    <td class="label"><label for="incoming_from">乡村主要收入来源：</label></td>
    <td><%= form.text_field :incoming_from %><br />
        <span class="tip">点击链接可以直接添加到输入框中，其他需求请自己输入并以空格隔开</span><br />
  		  <span id="incoming_from_tags">
  		    <%= tags_selector_for "incoming_from", %w(农业 手工业 畜牧业 旅游业) %>
  		  </span></td></td>
  </tr>
  <tr>
    <td><label for="incoming_average">当地年人均收入：</label></td>
    <td><select id="school_incoming_average" name="school[incoming_average]">
      <% Status::School::INCOMING_AVERAGE.each_with_index do |p, i| -%>
        <option value ="<%= i %>"><%= p %></option>
      <% end -%>
    </select></td>
  </tr>
  <tr>
    <td class="label"><label for="has_ngo">是否有公益组织或<br />民间人士资助：</label></td>
    <td><%= form.radio_button :has_ngo, Status::School::RadioBox::YES, :onclick => "Element.show('ngo-1')" %> 是，<%= form.radio_button :has_ngo, Status::School::RadioBox::NO, :onclick => "Element.hide('ngo-1')" %> 否，<%= form.radio_button :has_ngo, Status::School::RadioBox::UNKNOWN, :onclick => "Element.hide('ngo-1')" %> 未知</td>
  </tr>
  <tr id="ngo-1" <%= "style=\"display:none\"" unless @school.has_ngo==Status::School::RadioBox::YES %>>
    <td></td>
    <td><table border="0" cellspacing="2" cellpadding="0">
      <tr>
        <td><label for="ngo_name">组织名称：</label></td>
        <td><%= form.text_field :ngo_name %></td>
      </tr>
      <tr>
        <td><label for="ngo_start_at">开展时间：</label></td>
        <td><%= form.date_select :ngo_start_at, :use_month_names => Status::MONTHS, :start_year => 1980 %></td>
      </tr>
      <tr>
        <td><label for="ngo_contact_name">联系人：</label></td>
        <td><%= form.text_field :ngo_contact_name %></td>
      </tr>
      <tr>
        <td><label for="ngo_contact_via">联系方式：</label></td>
        <td><%= form.text_field :ngo_contact_via %></td>
      </tr>
    </table></td>
  </tr>  
</table>

<h2>交通指南(从临近城市或景点到该学校的交通)</h2>
<table border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td><label for="traffic_sights">附近景点：</label></td>
    <td><%= form.text_field :traffic_sights %></td>
  </tr>
  <tr>
    <td><label for="traffic_type">交通方式：</label></td>
    <td><%= form.text_field :traffic_type %><br />
        <span style="color:gray">点击链接可以直接添加到输入框中，其他需求请自己输入并以空格隔开</span><br />
    		<span id="traffic_type_tags"><%= tags_selector_for "traffic_type", %w(火车 汽车 骑车 步行) %></span>
    </td>
  </tr>
  <tr>
    <td><label for="traffic_duration">路程时间：</label></td>
    <td><%= form.text_field :traffic_duration %> 小时</td>
  </tr>
  <tr>
    <td class="label"><label for="traffic_description">路程攻略：</label></td>
    <td><%= form.text_area :traffic_description, :rows => 8, :cols => 60 %></td>
  </tr>
  <tr>
    <td><label for="traffic_charge">交通费用：</label></td>
    <td><%= form.text_field :traffic_charge %> 元</td>
  </tr>
</table>

<h2>学校需求</h2>
<p><span class="tip">点击链接可以直接添加到输入框中，其他需求请自己输入<br />
  <strong><span style="color:red">以空格隔开</span>，不要使用逗号、顿号或其它标点进行分割</strong></span></p>
<table border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td><label for="books_need">书籍类：</label></td>
    <td><%= form.text_field :books_need %>
        <%= tags_selector_for "books_need", %w(教辅 字典 课外书) %></td>
  </tr>
  <tr>
    <td><label for="stationaries_need">文具类：</label></td>
    <td><%= form.text_field :stationaries_need %>
        <%= tags_selector_for "stationaries_need", %w(笔 橡皮 文具盒 书包 本子) %></td>
  </tr>
  <tr>
    <td><label for="sports_need">文体类：</label></td>
    <td><%= form.text_field :sports_need %>
        <%= tags_selector_for "sports_need", %w(球类 跳绳 棋类 益智类) %></td>
  </tr>
  <tr>
    <td><label for="clothes_need">衣服类：</label></td>
    <td><%= form.text_field :clothes_need %>
        <%= tags_selector_for "clothes_need", %w(棉衣 运动服 鞋子) %></td>
  </tr>
  <tr>
    <td><label for="accessories_need">教具类：</label></td>
    <td><%= form.text_field :accessories_need %>
        <%= tags_selector_for "accessories_need", %w(尺子 圆规 三角板 粉笔) %></td>
  </tr>
  <tr>
    <td><label for="classes_need">学校活动需求：</label></td>
    <td><%= form.text_field :classes_need %>
        <%= tags_selector_for "classes_need", %w(电脑课 音乐课 环保课 安全自救培训 英语课) %></td>
  </tr>
  <tr>
    <td><label for="teachers_need">支教老师：</label></td>
    <td><%= form.text_field :teachers_need %>
        <%= tags_selector_for "teachers_need", %w(语文老师 数学老师 英语老师 音体美老师) %></td>
  </tr>
  <tr>
    <td><label for="others_need">其它类：</label></td>
    <td><%= form.text_field :others_need %>
        <%= tags_selector_for "others_need", %w(实验用具 课桌椅 玩具) %></td>
  </tr>
</table>

<h2>信息收集人</h2>
<table border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td><label for="finder_name">收集人姓名：</label></td>
    <td><%= form.text_field :finder_name %></td>
  </tr>
  <tr>
    <td><label for="finder_email">Email：</label></td>
    <td><%= form.text_field :finder_email %></td>
  </tr>
  <tr>
    <td><label for="finder_qq">QQ：</label></td>
    <td><%= form.text_field :finder_qq %></td>
  </tr>
  <tr>
    <td><label for="finder_msn">MSN：</label></td>
    <td><%= form.text_field :finder_msn %></td>
  </tr>
  <tr>
    <td><label for="finder_survey_at">调查时间：</label></td>
    <td><%= form.date_select :finder_survey_at, :use_month_names => Status::MONTHS, :start_year => 1980, :end_year => 2010 %></td>
  </tr>
</table>

<h2>学校受灾情况</h2>
<p><%= form.text_area :advice, :rows => 8, :cols => 60 %></p>
<script type="text/javascript">
String.prototype.trim = function() { a = this.replace(/^\s+/, ''); return a.replace(/\s+$/, ''); };
var lastEdit = "";

function swap(inputedTags, tag) {
  //alert(inputedTags);
  inputedTags = $("school_" + inputedTags);
	var tagArray = inputedTags.value.trim().split(' ');
	var present = false;
	var t, tl = tag.toLowerCase();
	
	if (tagArray[0].trim() == '') tagArray.splice(0,1);
	for (t=0; t<tagArray.length; t++) {
		if (tagArray[t].toLowerCase() == tl) { tagArray.splice(t,1); present = true; t-=1; }
	}
	if (!present) {tagArray.push(tag); }
	var content = tagArray.join(' ');
	lastEdit = inputedTags.value = (content.length > 1) ? content + ' ' : content;
	//alert(inputedTags.name);
	focusTo(inputedTags);
}
// focus the caret to end of a form input (+ optionally select some text)
var range=0 //ie
function focusTo(obj, selectFrom) {
  //alert(obj.name);
	if (typeof selectFrom == 'undefined') selectFrom = obj.value.length
	if(obj.createTextRange){ //ie + opera
		if (range == 0) range = obj.createTextRange()
		range.moveEnd("character",obj.value.length)
		range.moveStart("character",selectFrom)
		obj.select()
		range.select()
		setTimeout('range.select()', 10)
	} else if (obj.setSelectionRange){ //ff
		obj.select()
		obj.setSelectionRange(selectFrom,obj.value.length)
	} else { //safari :(
	  obj.blur()
  }
}
// set area's id to hidden field(id:school_area_id)
function select_area(id, title) {
  $('school_area_id').value = id;
  $('areas-list-notice').innerHTML = "您已将学校所在地选定为 " + title;
  $('area-title').innerHTML = title;
  Element.show('areas-list-notice');
  Element.hide('areas-list-spinner');
  Element.hide('areas-list');
}
</script>